const path = require('path')
const compression = require('compression')
const express = require('express')
const app = express()
const proxy = require('http-proxy-middleware')
const ejs = require('ejs')
const indexRouter = require('./index')
const config = require('./server.config')

app.use(compression())

// 模板配置
app.engine('html', ejs.__express)
app.set('view engine', 'html')
app.set('views', path.join(__dirname, '../dist'))

// 静态资源配置
app.use('/', express.static(path.join(__dirname, '../dist')))

// api代理配置
app.use('/api', proxy({
  target: config.proxy,
  changeOrigin: true,
}))

// 路由配置
app.use('/', indexRouter)

// 监听端口
app.listen(config.port)
